{extend name="base" /}
{block name="title"}修改密码{/block}
{block name="head"}{/block}
{block name="body"}
<div class="page-hd"></div>
<div class="page-bd">
<form method="POST">
  <div class="weui_cells weui_cells_form" style="margin-top:0">
    <div class="weui_cell">
      <div class="weui_cell_hd"><label class="weui_label">新密码</label></div>
      <div class="weui_cell_bd weui_cell_primary">
        <input class="weui_input" type="password" name="pwd1" maxlength="16" placeholder="请输入新密码" />
      </div>
      <div class="weui_cell_ft"><i class="weui_icon_warn"></i></div>
    </div>
    <div class="weui_cell">
      <div class="weui_cell_hd"><label for="" class="weui_label">新密码</label></div>
      <div class="weui_cell_bd weui_cell_primary">
        <input class="weui_input" type="password" name="pwd2" maxlength="16" placeholder="再次请输入新密码" />
      </div>
      <div class="weui_cell_ft"><i class="weui_icon_warn"></i></div>
    </div>
  </div>
  <div class="weui_btn_area">
    <input type="submit" class="weui_btn weui_btn_primary" value="提交" />
  </div>
</form>
</div>
{/block}
{block name="foot"}
<script>
$(function () {
  var $form = $("form")
  var $pwd1 = $("input[name='pwd1']");
  var $pwd2 = $("input[name='pwd2']");
  var $cel1 = $pwd1.parents('.weui_cell');
  var $cel2 = $pwd2.parents('.weui_cell');

  $form.submit(function () {

    ///////
    var va = $pwd1.val();
    var la = va.length;
    if (la == 0) {
      $.toptips('请输入新密码');
      $cel1.addClass('weui_cell_warn');
      return false;
    }
    if (la < 6 || la > 16) {
      $.toptips('新密码长度为6-16');
      $cel1.addClass('weui_cell_warn');
      return false;
    }
    ///////
    var vb = $pwd2.val();
    var lb = vb.length;
    if (lb == 0) {
      $.toptips('请输入新密码');
      $cel2.addClass('weui_cell_warn');
      return false;
    }
    if (lb < 6 || lb > 16) {
      $.toptips('新密码长度为6-16');
      $cel2.addClass('weui_cell_warn');
      return false;
    }
    ///////
    if (va != vb) {
      $.toptips('两个密码不一致');
      return false;
    }

    var data = $form.serialize();
    console.log(data);
    
    $.ajax({
      type: 'POST',
      url: "{:url('resetpwd')}",
      data: data,
      beforeSend: function () {
        $.showLoading('正在提交');
      },
      complete: function () {
        $.hideLoading();
      },
      success(resp, text, xhr) {
        $.alert(resp.error, function () {
          if (resp.errno == 0) {
            location.replace("{:url('exit')}");
          }
        });
      }
    });
    return false;
    
  });
  
  $("input[type='password']").focus(function(){
    var _this = $(this);
    var _elem = _this.parents('.weui_cell');
    _elem.removeClass('weui_cell_warn');
  });

});
</script>
{/block}